<template>
  <div class="form-item" :class="formTypeClass" @click="clickCnt++">
    <div>
      <template v-if="formField">
        <div v-if="fieldType == 'Text'">
          <textInput
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'Date'">
          <datePicker
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'DateRange'">
          <daterangePicker
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'Number'">
          <numberInput
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'Selection'">
          <selection
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'MultiSelection'">
          <multiSelection
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'CheckBox'">
          <checkBox
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'CompanySelection'">
          <companySelection
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'EmployeeSelection'">
          <employeeSelection
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'FileUpload'">
          <fileUpload
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'AreaSelection'">
          <areaSelection
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'CompanyMultiSelection'">
          <companyMultiSelection
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'EmployeeMultiSelection'">
          <employeeMultiSelection
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
        <div v-else-if="fieldType == 'DetailList'">
          <detailList
            :creatorId="creatorId"
            :value="fieldValue"
            :props="formField.props"
            :disabled="disabled"
            @input="dataInput"
            @display="dataDisplay"
            :required="required"
            :isBusiness="isBusiness"
          />
        </div>
      </template>

      <template v-else>请设置字段</template>
    </div>
  </div>
</template>
<script>
import textInput from '@/views/phone/form/formField/textInput.vue'
import numberInput from '@/views/phone/form/formField/numberInput.vue'
import datePicker from '@/views/phone/form/formField/datePicker.vue'
import daterangePicker from '@/views/phone/form/formField/daterangePicker.vue'
import selection from '@/views/phone/form/formField/selection.vue'
import multiSelection from '@/views/phone/form/formField/multiSelection.vue'
import companySelection from '@/views/phone/form/formField/companySelection.vue'
import companyMultiSelection from '@/views/phone/form/formField/companyMultiSelection.vue'
import employeeSelection from '@/views/phone/form/formField/employeeSelection.vue'
import employeeMultiSelection from '@/views/phone/form/formField/employeeMultiSelection.vue'
import fileUpload from '@/views/phone/form/formField/fileUpload.vue'
import areaSelection from '@/views/phone/form/formField/areaSelection.vue'
import checkBox from '@/views/phone/form/formField/checkBox.vue'
import detailList from '@/views/phone/form/formField/detailList.vue'
import '@/styles/form.css'
export default {
  components: {
    textInput,
    numberInput,
    datePicker,
    daterangePicker,
    selection,
    multiSelection,
    checkBox,
    companySelection,
    companyMultiSelection,
    employeeSelection,
    employeeMultiSelection,
    fileUpload,
    areaSelection,
    detailList,
  },
  props: ['formField', 'isBusiness', 'form'],
  data: function () {
    return {
      clickCnt: 0,
    }
  },
  methods: {
    dataInput(val) {
      if (JSON.stringify(val) != JSON.stringify(this.formField.FFV_Value)) {
        this.$emit('change', val)
      }
      this.formField.FFV_Value = val
    },
    dataDisplay(val) {
      this.formField.FFV_DisplayValue = val
    },
  },
  computed: {
    name() {
      let val = this.formField.props
        ? this.formField.props.find((x) => x.FLPR_Code == 'name')
        : null
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : '地区1'
        } else {
          return val.FFLP_Value ? val.FFLP_Value : val.FF_DisplayName
        }
      }
      return '地区'
    },
    creatorId() {
      return this.form?.WFM_CreateEmpId
    },
    fieldValue() {
      return this.formField.FFV_Value
    },
    fieldType() {
      return this.formField ? this.formField.FFLD_TypeDesc : null
    },
    required() {
      return this.isBusiness
        ? this.formField.BFF_Require
        : this.formField.FF_Require
    },
    disabled() {
      if (this.clickCnt >= 10) {
        return false
      }
      return this.formField.FFV_Disable
    },
    formTypeClass() {
      return [
        'FileUpload',
        'CompanyMultiSelection',
        'EmployeeMultiSelection',
        'CaseDetailSelection',
        'CaseLogSelection',
        'PersonalInvoiceSelection',
        'DetailList',
        'CaseChargeDetail',
        'EmployeeSelection',
        'CompanySelection',
      ].indexOf(this.fieldType) > 0
        ? 'form-item-border'
        : ''
    },
  },
}
</script>
<style scoped>
</style>